# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Andy Postnikov <apostnikov@gmail.com>
pkgname=phpspy
pkgver=0.6.0
_termbox2=915b186bdc94c6a79537dbe1e7479af2d26f5081
pkgrel=0
pkgdesc="Low-overhead sampling profiler for PHP"
url="https://github.com/adsr/phpspy"
arch="all"
license="MIT"
depends="perl"
makedepends="linux-headers"
checkdepends="ncurses bash grep php82 procps"
options="!check" # require ptrace capability and checkroot is not enough
source="$pkgname-$pkgver.tar.gz::https://github.com/adsr/phpspy/archive/v$pkgver.tar.gz
	termbox2-$_termbox2.tar.gz::https://github.com/termbox/termbox2/archive/$_termbox2.tar.gz
	"

prepare() {
	default_prepare
	rm -fr "$builddir"/vendor/termbox2
	ln -sfTv "$srcdir"/termbox2-$_termbox2 "$builddir"/vendor/termbox2
}

build() {
	make phpspy
}

check() {
	# require sudo and ptrace capability
	rm \
		tests/test_pgrep.sh \
		tests/test_pgrep_time_limit.sh \
		tests/test_pgrep_trace_limit.sh \
		tests/test_pid.sh \
		tests/test_time_limit.sh \
		-fv
	TERM=xterm make test
}

package() {
	make prefix="/usr" DESTDIR="$pkgdir" install
	install -D -v -m 755 stackcollapse-phpspy.pl \
		"$pkgdir"/usr/bin/stackcollapse-phpspy
	install -D -v -m 755 vendor/flamegraph.pl \
		"$pkgdir"/usr/bin/flamegraph-phpspy
}

sha512sums="
7667f754e8c242ef72b6e4fd3715fb19d9561419a2cd1c6f0961a2da1c8a5493191e476b9934f5b9cb322ac0102c955c158ca90a6f563f174111f9ed3a901487  phpspy-0.6.0.tar.gz
8c6b64a318671975a0678928726319c20ac2356570ef232d73bd969da32f93efbd1f0f2cbb2983665d7fe8353c08c345690c81c680324a074eac1b811d780571  termbox2-915b186bdc94c6a79537dbe1e7479af2d26f5081.tar.gz
"
